.text
Pf:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
#[Allocate space for temps
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
#]
#[Procedure body
    lw $t0, 8($fp)	 #right operand value in $t0
    lw $t1, 4($fp)	 #left operand value in $t1
    add $t2, $t1, $t0
    sw $t2, 8($sp)	 #store word into destination address
    lw $t0, 8($sp)	 #store in $t0 value of #4
    sw $t0, 4($sp)	 #store word in $t0 into RV
    b R0
R0:
    lw $v0, 4($sp)	 #save the return value to $V0
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    li $t0, 0
    sub $t1, $fp, $t0
    lw $fp, ($t1)	 #restore fp
    jr $ra	 #goto the return address
#]
.text
main:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
#[Allocate space for temps
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
#]
#[Procedure body
    li $t0, 1	 #load integer  into $t0
    sw $t0, 12($sp)	 #store integer in $t0 into #6
    li $t0, 3	 #load integer  into $t0
    sw $t0, 16($sp)	 #store integer in $t0 into #7
    li $t0, 0	 #load integer  into $t0
    sw $t0, 20($sp)	 #store integer in $t0 into #8
    lw $t0, 16($sp)	 #right operand value in $t0
    lw $t1, 20($sp)	 #left operand value in $t1
    seq $t2, $t1, $t0
    sw $t2, 24($sp)	 #store word into destination address
    lw $t0, 24($sp)	 #right operand value in $t0
    lw $t1, 12($sp)	 #left operand value in $t1
    sne $t2, $t1, $t0
    sw $t2, 28($sp)	 #store word into destination address
    li $t0, 4	 #load integer  into $t0
    sw $t0, 32($sp)	 #store integer in $t0 into #11
    lw $t0, 32($sp)	 #store in $t0 value of #11
    beqz $t0, L0	 #jump if #11 contains zero
    li $t0, 6	 #load integer  into $t0
    sw $t0, 36($sp)	 #store integer in $t0 into #12
    lw $t0, 36($sp)	 #store in $t0 value of #12
    sw $t0, 32($sp)	 #store word in $t0 into #11
    b L1
L0:
    li $t0, 0	 #load integer  into $t0
    sw $t0, 32($sp)	 #store integer in $t0 into #11
L1:
    li $t0, 7	 #load integer  into $t0
    sw $t0, 40($sp)	 #store integer in $t0 into #13
    li $t0, 8	 #load integer  into $t0
    sw $t0, 44($sp)	 #store integer in $t0 into #14
    lw $t0, 44($sp)	 #right operand value in $t0
    lw $t1, 40($sp)	 #left operand value in $t1
    mul $t2, $t1, $t0
    sw $t2, 48($sp)	 #store word into destination address
    li $t0, 10	 #load integer  into $t0
    sw $t0, 52($sp)	 #store integer in $t0 into #16
    lw $t0, 52($sp)	 #right operand value in $t0
    lw $t1, 48($sp)	 #left operand value in $t1
    add $t2, $t1, $t0
    sw $t2, 56($sp)	 #store word into destination address
    li $t0, 11	 #load integer  into $t0
    sw $t0, 60($sp)	 #store integer in $t0 into #18
    li $t0, 12	 #load integer  into $t0
    sw $t0, 64($sp)	 #store integer in $t0 into #19
    lw $t0, 64($sp)	 #right operand value in $t0
    lw $t1, 60($sp)	 #left operand value in $t1
    sub $t2, $t1, $t0
    sw $t2, 68($sp)	 #store word into destination address
    li $t0, 12	 #load integer  into $t0
    sw $t0, 72($sp)	 #store integer in $t0 into #21
    li $t0, 16	 #load integer  into $t0
    sw $t0, 76($sp)	 #store integer in $t0 into #22
    lw $t0, 76($sp)	 #right operand value in $t0
    lw $t1, 72($sp)	 #left operand value in $t1
    div $t2, $t1, $t0
    sw $t2, 80($sp)	 #store word into destination address
    move $t9, $sp
    lw $t0, 80($t9)	 #load #23contents
    sw $t0, ($sp)	 #push a arg of callee into stack
    li $t1, 4
    sub $sp, $sp, $t1
    lw $t0, 68($t9)	 #load #20contents
    sw $t0, ($sp)	 #push a arg of callee into stack
    li $t1, 4
    sub $sp, $sp, $t1
    jal Pf	 #goto the procedure
    addi $sp, $sp, 8
    sw $v0, 84($sp)	 #store returned result
    li $t0, 17	 #load integer  into $t0
    sw $t0, 88($sp)	 #store integer in $t0 into #25
    li $t0, 18	 #load integer  into $t0
    sw $t0, 92($sp)	 #store integer in $t0 into #26
    lw $t0, 92($sp)	 #right operand value in $t0
    lw $t1, 88($sp)	 #left operand value in $t1
    sle $t2, $t1, $t0
    sw $t2, 96($sp)	 #store word into destination address
    li $t0, 20	 #load integer  into $t0
    sw $t0, 100($sp)	 #store integer in $t0 into #28
    lw $t0, 100($sp)	 #right operand value in $t0
    lw $t1, 96($sp)	 #left operand value in $t1
    slt $t2, $t1, $t0
    sw $t2, 104($sp)	 #store word into destination address
    li $t0, 21	 #load integer  into $t0
    sw $t0, 108($sp)	 #store integer in $t0 into #30
    li $t0, 22	 #load integer  into $t0
    sw $t0, 112($sp)	 #store integer in $t0 into #31
    lw $t0, 112($sp)	 #right operand value in $t0
    lw $t1, 108($sp)	 #left operand value in $t1
    seq $t2, $t1, $t0
    sw $t2, 116($sp)	 #store word into destination address
    lw $t0, 116($sp)	 #store in $t0 value of #32
    sw $t0, 8($sp)	 #store word in $t0 into #5
    li $t0, 25	 #load integer  into $t0
    sw $t0, 120($sp)	 #store integer in $t0 into #33
    li $t0, 27	 #load integer  into $t0
    sw $t0, 124($sp)	 #store integer in $t0 into #34
    lw $t0, 124($sp)	 #right operand value in $t0
    lw $t1, 120($sp)	 #left operand value in $t1
    sge $t2, $t1, $t0
    sw $t2, 128($sp)	 #store word into destination address
    li $t0, 28	 #load integer  into $t0
    sw $t0, 132($sp)	 #store integer in $t0 into #36
    lw $t0, 132($sp)	 #right operand value in $t0
    lw $t1, 128($sp)	 #left operand value in $t1
    sgt $t2, $t1, $t0
    sw $t2, 136($sp)	 #store word into destination address
R1:
    lw $v0, 4($sp)	 #save the return value to $V0
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    li $t0, 0
    sub $t1, $fp, $t0
    lw $fp, ($t1)	 #restore fp
    jr $ra	 #goto the return address
#]
.globl Pputint
.text
Pputint:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
    li $v0, 1
    lw $a0, 4($fp)
    syscall
#[Restore registers, FP and SP
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    lw $fp, ($fp)	 #restore fp
#]
    jr $ra	 #goto the return address
.globl Pputstring
.text
Pputstring:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
    li $v0, 4
    lw $a0, 4($fp)
    syscall
#[Restore registers, FP and SP
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    lw $fp, ($fp)	 #restore fp
#]
    jr $ra	 #goto the return address
.globl Pgetint
.text
Pgetint:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
    li $v0, 5
    syscall
#[Restore registers, FP and SP
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    lw $fp, ($fp)	 #restore fp
#]
    jr $ra	 #goto the return address
.globl Pgetstring
.text
Pgetstring:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
    li $v0, 8
    lw $a0, 4($fp)
    li $a1, 80
    syscall
#[Restore registers, FP and SP
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    lw $fp, ($fp)	 #restore fp
#]
    jr $ra	 #goto the return address
